package main

import (
	"fmt"
	"go-tour/interface/blank/blank"
)

/*
https://www.cnblogs.com/waitmoon/p/13956393.html
golang中的接口，类型不空，值为空，如何判断是nil？
*/

type Person struct {
	Name string
}

func (*Person) GetName() {

}

type ITester interface {
	GetName()
}

func main() {
	var i interface{} = nil //空值
	fmt.Println("空值")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))
	fmt.Println("-----------")
	i = "" //字符串空值
	fmt.Println("字符串空值")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))
	fmt.Println("-----------")
	i = []int(nil) //切片
	fmt.Println("切片")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))
	fmt.Println("-----------")
	i = map[int]int(nil) //映射
	fmt.Println("映射")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))
	fmt.Println("-----------")
	i = chan int(nil) //通道
	fmt.Println("通道")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))
	fmt.Println("-----------")
	i = (func())(nil) //函数
	fmt.Println("函数")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))
	fmt.Println("-----------")
	i = (*int)(nil) //指针
	fmt.Println("指针")
	fmt.Println("==判断：", i == nil)
	fmt.Println("异常判断：", blank.InterfaceIsNil1(i))
	fmt.Println("类型判断：", blank.InterfaceIsNil2(i))

}

